package com.liusand.activity.controller;

import com.liusand.activity.service.ActivityService;
import com.liusand.entity.dto.ActivityInfoDto;
import com.liusand.entity.vo.MoneyVo;
import com.liusand.entity.vo.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :liusha
 * packageName :com.liusand.activity.controller
 * fileName :ActivityController
 * creationTime :2022/12/22 15:38
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {


    @Autowired
    private ActivityService activityService;

    @PostMapping("/redPackage")
    public Result addActivity(@RequestBody ActivityInfoDto activityInfoDto){
        if(activityInfoDto == null
                || activityInfoDto.getAmount() == null
                || activityInfoDto.getMoney() == null
                || activityInfoDto.getEndTime() == null
                || activityInfoDto.getStartTime() == null
                || StringUtils.isEmpty(activityInfoDto.getName())){
            return Result.error("添加失败");
        }
        boolean result = activityService.addActivity(activityInfoDto);
        if(!result){
            return Result.error("添加失败");
        }
        return Result.success("创建成功");
    }

    @GetMapping("/redPackage")
    public Result getRedPackage(){
        MoneyVo money = activityService.getRedPackage();
        return Result.success(money);
    }
}
